using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
using SpoonCore2.Client;
using SpoonCore2.Message.Header;
using SpoonCore2.Message.Header.Option;
using SpoonCore2.Service;
using System.Timers;

namespace SpoonCore2.Message.Header.Handler
{
	class AcknowledgmentOptionHandler : IMessageOptionHandler<AcknowledgmentOption>
	{
		private static readonly TimeSpan Timeout = new TimeSpan(0, 0, 10);
		private readonly Timer _checkTimer = new Timer(1000);
		private ServiceManager _manager;
		private readonly SortedList<int, AcknowledgItem> _itemList = new SortedList<int, AcknowledgItem>();

		public AcknowledgmentOptionHandler()
		{
			_checkTimer.Elapsed += _checkTimer_Elapsed;
			_checkTimer.Start();
		}

		private void _checkTimer_Elapsed(object sender, ElapsedEventArgs e)
		{

		}

		public void Send(ClientInfo destination, IMessage message, AcknowledgmentOption option, BinaryWriter bw)
		{
			option.Type = AcknowledgmentOption.AcknowledgType.Request;
			_itemList.Add(option.SeqId, new AcknowledgItem(destination, message));
		}

		public void Receive(ClientInfo source, IMessage message, AcknowledgmentOption option, BinaryReader br)
		{
			if(option.Type == AcknowledgmentOption.AcknowledgType.Request)
			{
				
			}
			else if(option.Type == AcknowledgmentOption.AcknowledgType.Response)
			{
				
			}
		}

		public IMessageOption Option
		{
			get { return new AcknowledgmentOption(); }
		}

		public void SetManager(ServiceManager manager)
		{
			_manager = manager;
		}

		private class AcknowledgItem
		{
			public DateTime Date = DateTime.Now;
			public ClientInfo Client;
			public IMessage Message;

			public AcknowledgItem(ClientInfo clientInfo, IMessage message)
			{
				Client = clientInfo;
				Message = message;
			}
		}
	}
}